<template>
  <div class="login-box">
    <el-form
      :model="form"
      status-icon
      :rules="rules"
      ref="form"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="账号" prop="username">
        <el-input
          v-model="form.username"
  
        ></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          type="password"
          v-model="form.password"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<style>
.login-box{
display: flex;
justify-content: center;

}

.demo-ruleForm{
    width: 400px;
    margin-top: 300px;
}
</style>

<script>
import Cookie from 'js-cookie'
import { getMenu } from '../api/idnex.js';


export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },

      rules: {
        username:[
        { required: true, message: '请输入账号', trigger: 'blur' },
        ],
        password:[
        { required: true, message: '请输入密码', trigger: 'blur' },
        ],

        }
    };
  },

  methods:{
    submitForm(){
        this.$refs.form.validate((val)=>{
            if(val){
                getMenu(this.form).then(({data})=>{
                    console.log(data);
                    if(data.code===20000){
                        Cookie.set('token',data.data.token)


                        this.$router.push('/home')
                    }else{
                        this.$message.error(data.data.message)
                    }



                })

                

            }
        })
    }
  }
};
</script>
